home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
windows
/
wdj1096.zip
/
ZOLMAN.ZIP
/
DRAW.ZIP
/
DRAWCTL.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-22
|
8KB
|
279 lines
// DrawCtl.cpp : Implementation of the CDrawCtrl OLE control class.
#include "stdafx.h"
#include "Draw.h"
#include "ParkWnd.h"
#include "DrawCtl.h"
#include "DrawPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CDrawCtrl, COleControl)
#define ID_BUTTON 1000
#define ID_EDIT 1001
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CDrawCtrl, COleControl)
//{{AFX_MSG_MAP(CDrawCtrl)
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CDrawCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CDrawCtrl)
// NOTE - ClassWizard will add and remove dispatch map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CDrawCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CDrawCtrl, COleControl)
//{{AFX_EVENT_MAP(CDrawCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CDrawCtrl, 1)
PROPPAGEID(CDrawPropPage::guid)
END_PROPPAGEIDS(CDrawCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CDrawCtrl, "DRAW.DrawCtrl.1",
0x23c3763, 0xb40a, 0x11cf, 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CDrawCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DDraw =
{ 0x23c3761, 0xb40a, 0x11cf, { 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94 } };
const IID BASED_CODE IID_DDrawEvents =
{ 0x23c3762, 0xb40a, 0x11cf, { 0xa6, 0x4f, 0, 0xa0, 0x24, 0x25, 0xfb, 0x94 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwDrawOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CDrawCtrl, IDS_DRAW, _dwDrawOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::CDrawCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CDrawCtrl
BOOL CDrawCtrl::CDrawCtrlFactory::UpdateRegistry(BOOL bRegister)
{
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_DRAW,
IDB_DRAW,
TRUE, // Insertable
_dwDrawOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::CDrawCtrl - Constructor
CDrawCtrl::CDrawCtrl()
{
InitializeIIDs(&IID_DDraw, &IID_DDrawEvents);
// TODO: Initialize your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::~CDrawCtrl - Destructor
CDrawCtrl::~CDrawCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::OnDraw - Drawing function
void CDrawCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
//pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
//pdc->Ellipse(rcBounds);
if ( FALSE == IsWindowVisible() )
{
CWnd* pWndContainer = pdc->GetWindow();
if ( pWndContainer )
{
if ( NULL == m_wndParkingWnd.GetSafeHwnd() )
{
DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
if ( FALSE == m_wndParkingWnd.CreateEx (
WS_EX_CLIENTEDGE,
NULL,
NULL,
dwStyle,
rcBounds.left,
rcBounds.top,
rcBounds.Width(),
rcBounds.Height(),
pWndContainer->m_hWnd,
0))
return;
}
if (m_wndParkingWnd.m_hWnd != NULL)
m_wndParkingWnd.ShowWindow(SW_SHOW);
m_btnButton.SetParent ( &m_wndParkingWnd );
m_wndParkingWnd.pwndChild1 = (CWnd*)&m_btnButton;
m_btnButton.EnableWindow(FALSE);
m_edEdit.SetParent ( &m_wndParkingWnd );
m_wndParkingWnd.pwndChild2 = (CWnd*)&m_edEdit;
m_edEdit.EnableWindow(FALSE);
m_wndParkingWnd.MoveWindow ( rcBounds );
}
}
else
{
if ( NULL != m_wndParkingWnd.GetSafeHwnd() )
{
m_wndParkingWnd.ShowWindow(SW_HIDE);
m_btnButton.SetParent ( this );
m_btnButton.EnableWindow(TRUE);
m_edEdit.SetParent ( this );
m_edEdit.EnableWindow(TRUE);
m_wndParkingWnd.DestroyWindow();
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::DoPropExchange - Persistence support
void CDrawCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::OnResetState - Reset control to default state
void CDrawCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl::AboutBox - Display an "About" box to the user
void CDrawCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_DRAW);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CDrawCtrl message handlers
int CDrawCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if ( FALSE == m_btnButton.Create (
_T("Button"),
BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE,
CRect ( 0, 0, lpCreateStruct->cx, lpCreateStruct->cy/2 ),
this,
ID_BUTTON ) )
return -1;
if ( FALSE == m_edEdit.Create (
ES_CENTER | WS_CHILD | WS_VISIBLE,
CRect(0,lpCreateStruct->cy/2,lpCreateStruct->cx,lpCreateStruct->cy),
this,
ID_EDIT ) )
return -1;
return 0;
}
void CDrawCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_btnButton.MoveWindow(0, 0, cx, cy /2);
m_edEdit.MoveWindow(0, cy/2, cx, cy);
}